package com.boot.util;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;

public class JSONUtils {
    /**
     * 打印JSON
     * @param json
     * @param format
     */
    public static void printJSON(String json,boolean format){
        if(format){
            printJSON(json);
        }else{
            System.err.println(JSON.toJSONString(json));
        }
    }

    /**
     * JSON 格式化打印
     * @param str
     */
    public static void printJSON(String str){
        JSONObject object = JSONObject.parseObject(str);
        String pretty = JSON.toJSONString(object, SerializerFeature.PrettyFormat, SerializerFeature.WriteMapNullValue,
                SerializerFeature.WriteDateUseDateFormat);
        System.err.println(pretty);

    }

    /**
     * 打印JSON
     * @param obj
     */
    public static void printJSON(Object obj){
        printJSON(JSON.toJSONString(obj));
    }

}
